package com.neo4j.neo4jcloud.controller;

import com.neo4j.neo4jcloud.entity.CompanyGraph;
import com.neo4j.neo4jcloud.service.CompanyGraphService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author kabuqinuo
 * @date 2020/3/26 14:41
 */
@RestController
@RequestMapping(value = "/companyGraph")
public class CompanyGraphController {

    @Autowired
    private CompanyGraphService companyGraphService;

    @PostMapping
    public ResponseEntity<CompanyGraph> add(HttpServletRequest request, @RequestBody CompanyGraph companyGraph, HttpServletResponse response){
        return ResponseEntity.ok(companyGraphService.addCompanyGraph(companyGraph));
    }

    @GetMapping
    public ResponseEntity<CompanyGraph> findOne(HttpServletRequest request, @RequestParam(value = "id") Long id, HttpServletResponse response){
        return ResponseEntity.ok(companyGraphService.findOneByCompanyGraphId(id));
    }

    @DeleteMapping
    public String deleteOne(HttpServletRequest request, @RequestParam(value = "id") Long id, HttpServletResponse response){
        companyGraphService.deletOneByCompanyGraphId(id);
        return "success";
    }

    @GetMapping("/findOne")
    public ResponseEntity<CompanyGraph> findOne(HttpServletRequest request, @RequestParam(value = "nodeId") String nodeId, HttpServletResponse response){
        CompanyGraph companyGraph = companyGraphService.findOneByNodeId(nodeId);
        return ResponseEntity.ok(companyGraph);
    }
}
